package com.example.lss.news.fragment;


import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.lss.news.R;
import com.example.lss.news.adapter.ReAdapter;
import com.example.lss.news.bean.Data;
import com.example.lss.news.bean.Ress;
import com.example.lss.news.bean.Result;
import com.example.lss.news.utils.JsonUtils;
import com.example.lss.news.utils.app.BaseFrament;
import com.example.lss.news.utils.http.HttpUtils;
import com.example.lss.news.utils.http.JsonCallback;

import java.util.ArrayList;
import java.util.List;


public class GuoJiFragmet extends BaseFrament {
    private RecyclerView rv;
    ReAdapter reAdapter;
    private Ress<Result<List<Data>>> r = null;



    @Override
    protected View initView(LayoutInflater inflater, ViewGroup container) {
        View view = inflater.inflate(R.layout.frag_view, container, false);
        rv = view.findViewById(R.id.re);
        rv.addItemDecoration(new DividerItemDecoration(act, DividerItemDecoration.VERTICAL));
        return view;
    }

    @Override
    protected void initData() {
//        Toast.makeText(act, "连接点", Toast.LENGTH_SHORT).show();
        Boolean b=false;
        if (b==true)
        new Thread() {


            @Override
            public void run() {
                HttpUtils.get("http://v.juhe.cn/toutiao/index?type=guoji&key=9980cb57a9269e256bcc015d498dd572", new JsonCallback() {
                    @Override
                    public void onStart(Object tag) {

                    }

                    @Override
                    public void onSuccess(final String json) {


                        r = JsonUtils.toBean(json, JsonUtils.newParamType(Ress.class, JsonUtils.newParamType(Result.class, JsonUtils.newParamType(List.class, Data.class))));

                        if (r.getReason().equals("成功的返回")) {
                            List<Data> list = new ArrayList<>();
                            list.addAll(r.getResult().getData());
                            reAdapter = new ReAdapter(list);
                            rv.setLayoutManager(new LinearLayoutManager(act));
                            rv.setAdapter(reAdapter);
                        }
                    }

                    @Override
                    public void onError(Throwable exception) {

                    }

                    @Override
                    public void onFinish() {

                    }
                });
            }
        }.start();
    }
    @Override
    protected void initListener() {

    }
}
